import request from '@/config/axios'

// 规则库 VO
export interface RulesVO {
  rulesItems: any
  rulesId: number // 规则ID
  rulesName: string // 规则名称: 模板名称+规则名称或者规则名称
  rulesCode: string // 规则code
  rulesDay: number // 规则生效日期，适用于月送劵，如：每月10日
  sort: number // 显示顺序
  status: number // 状态（0正常 1停用）
  remark: string // 备注
}

// 规则库 API
export const RulesApi = {
  // 查询规则库分页
  getRulesPage: async (params: any) => {
    return await request.get({ url: `/system/rules/page`, params })
  },

  // 查询规则库详情
  getRules: async (id: number) => {
    return await request.get({ url: `/system/rules/get?rulesId=` + id })
  },
  // 新增规则库
  preCreateRules: async (data: { rulesCode: any }) => {
    return await request.post({ url: `/system/rules/pre-create`, data })
  },
  // 新增规则库
  createRules: async (data: RulesVO[]) => {
    return await request.post({ url: `/system/rules/create`, data })
  },

  // 修改规则库
  updateRules: async (data: RulesVO[]) => {
    return await request.put({ url: `/system/rules/update`, data })
  },

  // 删除规则库
  deleteRules: async (id: number) => {
    return await request.delete({ url: `/system/rules/delete?id=` + id })
  },

  // 导出规则库 Excel
  exportRules: async (params) => {
    return await request.download({ url: `/system/rules/export-excel`, params })
  },

  // ==================== 子表（规则项目） ====================

  // 获得规则项目列表
  // getRulesItemListByRulesId: async (rulesId) => {
  //   return await request.get({ url: `/system/rules/rules-item/list-by-rules-id?rulesId=` + rulesId })
  // }
  getRulesItemListByRulesCodes: async (data) => {
    return await request.post({
      url: `/system/dict-data/get-list`,
      data
    })
  }
}
